<template>
	<view class="apps">
		<uv-loading-page :loading="pageLoading" loading-text="正在加载..." font-size="14px" loading-mode="spinner"></uv-loading-page>
		<view class="list" v-for="(item,index) in list" @click="handle(item.id)">
			<view class="img">
				<image :src="item.image_url" style="width: 100%;height: auto;" mode="widthFix"></image>
			</view>
			<view class="info">
				<view class="title">{{item.title}}</view>
				<view class="time">
					<uv-icon name="clock-fill" ></uv-icon>
					<view style="margin-left: 10rpx;">{{item.start_time}}</view>
				</view>
				<view class="time">
					<uv-icon name="map-fill" ></uv-icon>
					<view style="margin-left: 10rpx;">{{item.city_text}}</view>
				</view>
				<view class="btw" >
					<view></view>
					<uv-tags text="已结束" type="error" plain plainFill  size="mini" v-if="item.process == 0 "></uv-tags>
					<uv-tags :text="item.nums==0?`报名中`:`已报名`+item.nums" plain plainFill  size="mini" v-else></uv-tags>
				</view>
			</view>
		</view>
		<view class="add-tap">
			
			<view class="tap" @click="handlepage('/pages/add/add')">
				<uv-icon name="plus" size="40px" color="#fff"></uv-icon>
			</view>
			<view style="height:10px"></view>
			<view class="tap" @click="handlepage('/pages/list/list')">
				<uv-icon name="list" size="40px" color="#fff"></uv-icon>
			</view>
		</view>
	</view>
</template>

<script>
	let app;
	import * as ww from '@wecom/jssdk'
	export default {
		data() {
			return {
				pageLoading:true,
				pageMore:true,
				page:1,
				pageSize:20,
				list:[]
			}
		},
		onLoad(opt) {
			if(opt.token){
				uni.setStorageSync('WeApp_token',opt.token);
			}
			app = this;
			ww.register({
				corpId: 'ww5d7b19c3c1ce8e1f',    // 必填，当前用户企业所属企业ID
				jsApiList: ['hideAllNonBaseMenuItem','hideOptionMenu','createWWLoginPanel'],   
				agentId:'1000008',
				getConfigSignature: async function(){
				  const configData = await app.request({
						url: '/auth',
						data:{'agent_id':''}
					})
					//app.alert(JSON.stringify(configData));
					return configData.data;
				},                
				getAgentConfigSignature: async function(){
					const AgentConf = await app.request({
						url: '/auth',
						data:{'agent_id':'1000008'}
					})
					//app.alert(JSON.stringify(AgentConf));
					return AgentConf.data;
				}
			})
			ww.hideAllNonBaseMenuItem();
			ww.hideOptionMenu();
			app.getlist();
		},
		onReachBottom() {
			if(app.pageMore){
				app.getlist();
			}
		},
		methods: {
			handlepage(e){
				uni.navigateTo({
					url:e,
				})
			},
			handle(id){
				uni.navigateTo({
					url:'/pages/detail/detail?id='+id,
				})
			},
			getlist(){
				let page = app.page;
				let page_size = app.pageSize;
				app.pageLoading =true;
				app.request({
					url:"/index",
					data:{page:page,page_size:page_size},
					success:function(res){
						if(res.data.length < app.pageSize){
							app.pageMore = false;
						}
						if(res.code == 1){
							if(page == 1){
								app.list = res.data;
								
								if(res.data.length == 0){
									app.pageMore=false;
								}
							}else{
								app.list.push(...res.data);
							}
						}
						app.pageLoading = false;
					}
				})
			}
			
		}
	}
</script>

<style scoped>
	.list{margin:15rpx 10rpx; padding:15rpx;background-color: #eef0f9; display: flex; border-radius: 5rpx;}
	.list .img{width:320rpx; margin-right: 10rpx; min-height: 160rpx;}
	.list .info{flex:1;display: flex;flex-direction: column;}
	.list .info .title{font-size: 26rpx; margin-bottom: 15rpx;display: flex; overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		/* 控制行数 */
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;}
	.list .info .time{font-size: 22rpx; display: flex; align-items: center;}
	.list .info .btw{display: flex; justify-content: space-between;}
	.add-tap{bottom: 100px;right: 20px;width: 40px;height: 90px;position: fixed;z-index: 10;}
	.add-tap .tap{display: flex;flex-direction: column;align-items: center;flex: 1;height: 40px;justify-content: center;border-radius: 4px; background-color:#55aaff;}
</style>
